package com.nick.prototype;

import java.io.*;
import java.util.List;

/**
 * Created by xiaobao on 2017/7/18.
 */
public class Classroom implements Cloneable, Serializable{
    private Teacher teacher;
    private List<Student> students;

    @Override
    public Object clone() throws CloneNotSupportedException {
        Classroom o = (Classroom) super.clone();
        o.setTeacher((Teacher) teacher.clone());
        return o;
    }
    public Object serializableClone() throws Exception{
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        return objectInputStream.readObject();
    }

    public Classroom(Teacher teacher, List<Student> students) {
        this.teacher = teacher;
        this.students = students;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    @Override
    public String toString() {
        return "Classroom{" +
                "teacher=" + teacher +
                ", students=" + students +
                '}';
    }
}
